﻿#include "GLLInc.h"
#include "GLLLvlObj.h"
#include "GLLObjAnim.h"
#include "GLLLevel.h"
#include "GLLMacro.h"

namespace GLL
{
	LvlObj::LvlObj()
	{
		_lifeStatus = LS_New;
	}

	LvlObj::~LvlObj()
	{
	}

	void LvlObj::PutToLoadQueue()
	{
		LvlObjSrdPtr ptr = boost::dynamic_pointer_cast<LvlObj>(shared_from_this());
		GetMgr()->PutToLoadQueue(ptr);
	}

	bool LvlObj::OnUpdate( TimeMS ms)
	{
		if( ! HasLifeStatus(LS_Loaded)) return false;

		//交给子类接着处理
		return OnUpdate_LvlObj(ms);
	}

#define LOCK_LIFE_STATUS	LOCK_MUTEX(_statusMutex)

	void LvlObj::SetLifeStatus( LifeStatus ls )
	{
		LOCK_LIFE_STATUS;
		_lastSet = ls;
		_lifeStatus = LifeStatus(_lifeStatus | ls);
	}

	bool LvlObj::HasLifeStatus( LifeStatus ls )
	{
		LOCK_LIFE_STATUS;
		return (_lifeStatus & ls) == ls;
	}

	void LvlObj::RemoveLifeStatus( LifeStatus ls )
	{
		LOCK_LIFE_STATUS;
		_lifeStatus = LifeStatus(_lifeStatus & (~ls));
	}

};//GLL
